package xcmg.device.service.audit;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.crm.util.ActionResultUtil;
import xcmg.device.service.vo.delivery.BusinessOrderAuditParamVO;
import yb.ecp.fast.infra.infra.ActionResult;

import java.util.List;

public abstract class AbstractBusinessOrderAuditService implements IBusinessOrderAuditService{

    @Override
    public ActionResult audit(BusinessOrderAuditParamVO auditParam,String userId,String userName,boolean pass) {
        //基础参数校验
        ActionResult result = paramBaseCheck(auditParam,pass);
        if(!ActionResultUtil.judgeSuccess(result)){
            return result;
        }
        //业务参数校验
        result = paramBusinessCheck(auditParam);
        if(!ActionResultUtil.judgeSuccess(result)){
            return result;
        }
        //更新单据审核状态
        updateAuditStatus(auditParam,userId,userName,pass);
        return ActionResultUtil.successActionResult();
    }

    @Override
    public ActionResult paramBaseCheck(BusinessOrderAuditParamVO auditParam,boolean pass) {
        if(auditParam == null){
            return ActionResultUtil.errorActionResult(ErrorCode.IllegalArument.getCode(),"参数不能为空");
        }
        List<String> ids = auditParam.getIds();
        if(CollectionUtils.isEmpty(ids)){
            return ActionResultUtil.errorActionResult(ErrorCode.IllegalArument.getCode(),"请选择需要的数据");
        }
        String auditRemark = auditParam.getAuditRemark();
        //如果审核操作为审核拒绝则必须填写拒绝原因
        if(!pass && StringUtils.isEmpty(auditRemark)){
            return ActionResultUtil.errorActionResult(ErrorCode.IllegalArument.getCode(),"请填写审核意见");
        }
        return ActionResultUtil.successActionResult();
    }

}
